package com.example.lotterysystem.dao.mapper;

import com.example.lotterysystem.dao.dataobject.ActivityUserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityUserMapper {

    @Insert("<script>" +
            "insert into activity_user (activity_id,status,user_id,user_name)" +
            "values <foreach collection='items' item='item' index='index' separator=','>" +
            "(#{item.activityId},#{item.status},#{item.userId},#{item.userName})" +
            "</foreach>" +
            "</script>")
    @Options(useGeneratedKeys = true, keyProperty = "id",keyColumn = "id")
    void BatchInsert(@Param("items") List<ActivityUserDO> activityUserDOList);

    @Select("<script>" +
            " select *from activity_user " +
            "where activity_id=#{activityId} " +
            "and user_id in " +
            "<foreach collection='userIds' item='userId' open='(' separator=',' close=')'>" +
            "#{userId}" +
            "</foreach>"+
            "</script>")
    List<ActivityUserDO> batchSelectByAUIds(@Param("activityId") Long activityId,
                                            @Param("userIds") List<Long> userIds);

    @Update("<script>" +
            "update activity_user set status=#{name} " +
            " where activity_id= #{activityId} " +
            " and user_id in " +
            "<foreach collection='userIds' item='userId' open='(' separator=',' close=')'>" +
            " #{userId}" +
            " </foreach>" +
            "</script>")
    void batchUpdateStatus(@Param("activityId") Long activityId,
                           @Param("userIds") List<Long> userIds,
                           @Param("name") String name);
}
